package net.esj.basic.core.engine.util.logging;

import java.text.MessageFormat;

import org.apache.log4j.Logger;

public class Log4jLogger extends AbstractLogger{

	org.apache.log4j.Logger logger ;
	
	public Log4jLogger(String name) {
		super(name);
		logger = Logger.getLogger(name);
	}

	public Log4jLogger(Class clazz) {
		super(clazz);
		logger = Logger.getLogger(clazz);
	}

	@Override
	public void debug(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.debug(mf.format(args));
	}

	@Override
	public void debug(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.debug(mf.format(args),ex);
	}

	@Override
	public void error(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.error(mf.format(args));
	}

	@Override
	public void error(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.error(mf.format(args),ex);
	}

	@Override
	public void fatal(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.fatal(mf.format(args));
	}

	@Override
	public void fatal(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.fatal(mf.format(args),ex);
	}

	@Override
	public void info(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.info(mf.format(args));
	}

	@Override
	public void info(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.info(mf.format(args),ex);
	}

	@Override
	public boolean isDebugEnabled() {
		return true;
	}

	@Override
	public boolean isErrorEnabled() {
		return true;
	}

	@Override
	public boolean isFatalEnabled() {
		return true;
	}

	@Override
	public boolean isInfoEnabled() {
		return true;
	}

	@Override
	public boolean isTraceEnabled() {
		return true;
	}

	@Override
	public boolean isWarnEnabled() {
		return true;
	}

	@Override
	public void logger(String log, String comments, LEVEL level) {
		String afterCom = "LOG:["+log+"],COMMENTS:["+comments+"]";
		switch(level){
		case TRACE:
			logger.trace(afterCom);
			return;
		case DEBUG:
			logger.debug(afterCom);
			return;
		case INFO:
			logger.info(afterCom);
			return;
		case WARN:
			logger.warn(afterCom);
			return;
		case ERROR:
			logger.error(afterCom);
			return;
		case FATAL:
			logger.fatal(afterCom);
			return;
		default:
			logger.debug(afterCom);
			return;
		}
	}

	@Override
	public void logger(String log, String comments) {
		logger.info("LOG:["+log+"],COMMENTS:["+comments+"]");
	}

	@Override
	public void logger(String log) {
		logger.info(log);
	}

	@Override
	public void trace(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.trace(mf.format(args));

	}

	@Override
	public void trace(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.trace(mf.format(args),ex);


	}

	@Override
	public void warn(String msg, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.warn(mf.format(args));
	}

	@Override
	public void warn(String msg, Throwable ex, String... args) {
		MessageFormat mf = new MessageFormat(msg);
		logger.warn(mf.format(args),ex);
	}

}
